package com.enation.app.javashop.api.client;

import com.enation.app.javashop.model.promotion.pintuan.Pintuan;
import com.enation.app.javashop.service.trade.pintuan.PintuanManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author fk
 * @version v2.0
 * @Description: 拼团对外client
 * @date 2018/7/30 15:06
 * @since v7.0.0
 */
@RestController
@RequestMapping("/client/pintuan")
@Validated
@ApiIgnore
public class PintuanClientController {

    @Autowired
    private PintuanManager pintuanManager;

    /**
     * 获取拼团
     *
     * @param id 拼团主键
     * @return Pintuan  拼团
     */
    @GetMapping(value = "/{id}")
    public Pintuan getModel(@PathVariable Long id) {
        return pintuanManager.getModel(id);
    }

    /**
     * 停止一个活动
     *
     * @param promotionId
     */
    @PostMapping(value = "/promotion/{promotion_id}/close")
    public void closePromotion(@PathVariable("promotion_id") Long promotionId) {
        pintuanManager.closePromotion(promotionId);
    }

    /**
     * 开始一个活动
     *
     * @param promotionId
     */
    @PostMapping(value = "/promotion/{promotion_id}/open")
    public void openPromotion(@PathVariable("promotion_id") Long promotionId) {
        pintuanManager.openPromotion(promotionId);
    }

    @GetMapping(value = "/status/{status}")
    public List<Pintuan> get(@PathVariable("status")String status) {
        return pintuanManager.get(status);
    }
}
